/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.aptech.childcare.until;

import java.security.*;
import java.util.logging.Level;
import java.util.logging.Logger;
import sun.misc.BASE64Encoder;

/**
 *
 * @author BaoTien
 */
public class MD5Password {

    public static String getEncodedPassword(String pass){
//            throws NoSuchAlgorithmException {
//        MessageDigest md = MessageDigest.getInstance("MD5");
//
//        md.update(clearTextPassword.getBytes());
//
//        return HexString.bufferToHex(md.digest());
//    }
//
//    public static boolean testPassword(String clearTextTestPassword,
//            String encodedActualPassword)
//            throws NoSuchAlgorithmException {
//        String encodedTestPassword = MD5Password.getEncodedPassword(
//                clearTextTestPassword);
//
//        return (encodedTestPassword.equals(encodedActualPassword));
//    }
//
//    public static void main(String args[]) {
//        try {
//            System.out.println(getEncodedPassword("A0709K"));
//        } catch (NoSuchAlgorithmException ne) {
//            ne.printStackTrace();
//        }
        try {
            MessageDigest md = MessageDigest.getInstance("MD5");
            byte[] b = md.digest(pass.getBytes());
            BASE64Encoder base = new BASE64Encoder();
            return base.encode(b);
        } catch (NoSuchAlgorithmException ex) {
            Logger.getLogger(MD5Password.class.getName()).log(Level.SEVERE, null, ex);
        }
        return null;
    }
   }

